package com.fdb.smcts.redis;

import java.util.stream.Stream;

import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisNode;

public class CustomRedisClusterConfiguration extends RedisClusterConfiguration {

	// ip1:port1,ip2:port2,ip3:port3,ip4:port4,...
	public CustomRedisClusterConfiguration(String clusterNodesString) {
		super();
		Stream.of(clusterNodesString.split(",")) // 以','作为分隔符
				.map(s -> s.split(":"))// 将ip和port分割开
				.map(pair -> new RedisNode(pair[0], Integer.valueOf(pair[1]))) // 对每个ip-port对创建一个RedisNode
				.forEach(this::addClusterNode);
	}
}
